package com.lm.liaoming.tool.choosebirthday;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.TextView;


import com.lm.liaoming.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 韦敏敏
 */

public class MyPopUpWindowSex extends PopupWindow {
    private View mView;
    private TextView finish;
    public static String sex;
    private List<String> sexData;
    private LoopView chooseSex;
    private Context context;

    public MyPopUpWindowSex(Activity context, View.OnClickListener clickListener) {
        super(context);
        this.context = context;
        sex = "男";
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mView = inflater.inflate(R.layout.choose_sex_diaolog, null);

        finish = mView.findViewById(R.id.user_info_select_finish);
        chooseSex = mView.findViewById(R.id.user_info_choose_sex);

        initLoopView();
        // 设置按钮监听
        finish.setOnClickListener(clickListener);

        //设置PopupWindow的View
        this.setContentView(mView);
        //设置PopupWindow弹出窗体的宽
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        //设置PopupWindow弹出窗体的高
        this.setHeight(context.getResources().getDimensionPixelOffset(R.dimen.user_info_dialog_height));
        //设置PopupWindow弹出窗体可点击
        this.setFocusable(true);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xeef6f6f6);
//        设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);

        this.setAnimationStyle(R.style.livePopStyle);
    }

    private void initLoopView() {
        sexData = new ArrayList<String>();
        sexData.add("男");
        sexData.add("女");
        chooseSex.setListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(int index) {
                sex = sexData.get(index);
            }
        });
        chooseSex.setItems(sexData);
        chooseSex.setInitPosition(0);
        chooseSex.setTextSize(22);
        chooseSex.setNotLoop();
    }
}

